import { BasicColumn, useRender } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import moment from 'moment';

export const columns: BasicColumn[] = [
  {
    title: '任务编号',
    dataIndex: 'id',
  },
  {
    title: '任务名称',
    dataIndex: 'name',
  },
  {
    title: '所属流程',
    dataIndex: 'processName',
    customRender: ({ record }) => {
      return record.processInstance ? record.processInstance.name : '';
    },
  },
  {
    title: '流程发起人',
    dataIndex: 'startUserNickname',
    customRender: ({ record }) => {
      return record.processInstance ? record.processInstance.startUserNickname : '';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    customRender: ({ record }) => {
      const time = record.createTime;
      return time ? moment(time).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
  },
  {
    title: '状态',
    dataIndex: 'suspensionState',
    customRender: ({ text }) => {
      if (text === 1) {
        return useRender.renderTag('激活', 'success');
      } else if (text === 2) {
        return useRender.renderTag('挂起', 'warning');
      }
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '任务名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    field: 'createTime',
    label: '创建时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    componentProps: {
      valueFormat: 'X',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '岗位名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入岗位名称',
    },
  },
  {
    field: 'code',
    label: '岗位编码',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入岗位编码',
    },
  },
  {
    field: 'status',
    label: '状态',
    defaultValue: 0,
    component: 'Switch',
    colProps: { span: 8 },
    required: true,
    componentProps: {
      checkedValue: 1,
      unCheckedValue: 0,
    },
  },
  {
    field: 'sort',
    label: '序号',
    component: 'Input',
    required: true,
    defaultValue: '255',
    componentProps: {
      placeholder: '请输入岗位序号',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
